package com.qf.dao.impl;

import com.qf.dao.Daoregister;
import com.qf.domain.Student;
import com.qf.utils.JDBCUtils2;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class DaoRegisterIpl implements Daoregister {
    private JdbcTemplate jdb=new JdbcTemplate(JDBCUtils2.getDs());

    @Override
    public int daoRegister(Student stud) {
        String sql="insert into ya values(?,?,?)";
        int update = jdb.update(sql, stud.getId(), stud.getUsername(), stud.getPassword());
        return update;
    }

    @Override
    public Student findStudent(String count) {
        try {
            String sql = "select * from ya where username=?";
            Student student = jdb.queryForObject(sql, new BeanPropertyRowMapper<Student>(Student.class), count);
            return student;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
